﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GA.Server.ApiInfo;
using System.Xml;

namespace GA.Server.Api
{
    public class ApiInfoMission : SignedApiCall
    {
        public IEnumerable<ApiKill> Kills { get; private set; }
        public IEnumerable<ApiMissionDetail> MissionDetails { get; private set; }

        public ApiInfoMission()
        {
        }

        public ApiInfoMission(int clientId, string authorizationText, string sessionId)
            : base(clientId, authorizationText, sessionId)
        {
        }

        public void LoadApi(int mapInstanceId)
        {
            LoadSignedApiCall("m=" + mapInstanceId.ToString());

            XmlNodeList killNodes = XmlDocument.GetElementsByTagName("a:get_mission_kill_statsResult");
            List<ApiKill> kills = new List<ApiKill>();
            foreach (XmlNode killNode in killNodes)
            {
                kills.Add(new ApiKill(killNode.CreateNavigator().ReadSubtree()));
            }
            Kills = kills;

            XmlNodeList missionDetailNodes = XmlDocument.GetElementsByTagName("a:stats_get_mission_detailsResult");
            List<ApiMissionDetail> missionDetails = new List<ApiMissionDetail>();
            foreach (XmlNode missionDetailNode in missionDetailNodes)
            {
                missionDetails.Add(new ApiMissionDetail(missionDetailNode.CreateNavigator().ReadSubtree()));
            }
            MissionDetails = missionDetails;
        }

        protected override string ApiCallName
        {
            get { return "Mission"; }
        }
    }
}
